{ After a file is chooen, This procedure is call to open and draw the drawing to screen }
procedure  TPreviewForm.LoadTheDrawing(FileName: String);
const
    MM_TEXT = 1;  
var FormHwnd: HWND;
    var1, var2: Variant;       { These variables are declared as Variant, The Variant type is capable of }
                               { representing values that change type dynamically. When a variant contains }
                               { an OLE Automation object, the variant can be used to get and set properties }
                               { of the object, and to invoke methods on the object. }
    canvasRect: TRect;
begin

  { Check to see that the Application has been connected first }
   if (VarType(SDKApp) <> varEmpty) and (not VarIsNull(SDKApp)) and (FileName <> '') then
   begin
       try
       begin
           var1 := null;
           var2 := null;

        { Clear the PaintBox area first }
           PaintBox1.Canvas.Brush.Color := clWhite;
           wWidth := PaintBox1.Width;
           wHeight := PaintBox1.Height;
           wX := PaintBox1.Left;
           wY := PaintBox1.Top;
           canvasRect := Rect(0, 0, wWidth, wHeight);
           PaintBox1.Canvas.FillRect(canvasRect);

           { Close any previous open drawings and clear the Variant variables. Check if }
        { variables are NULL or undefined before operating on them }
           if (VarType(TheView) <> varEmpty) and (not VarIsNull(TheView)) then
           begin
              VarClear(TheView);
              TheView := NULL;
           end;

           if (VarType(SDKViews) <> varEmpty) and (not VarIsNull(SDKViews)) then
           begin
              VarClear(SDKViews);
              SDKViews := NULL;
           end;

           if (VarType(TheDrawing) <> varEmpty) and (not VarIsNull(TheDrawing)) then
           begin
               TheDrawing.Close(false);  { This closes the open drawing }
               VarClear(TheDrawing);
               TheDrawing := NULL;
           end;

         { We now call the open method (from the IMSI SDK) using the name of the file to open. }
         { This returns a drawing object represent the opened drawing. }
           TheDrawing := SDKDrawings.Open(FileName);

           { Get a reference to the Views container for the Drawing }
           SDKViews := TheDrawing.Views;

        { Add a specific view to the views container SDKViews. Notice that the Add method takes }
        { no parameters. yet if you look at the method definition in the SDK (C++)  you will see it has }
        { three parameters:
              HRESULT Views::Add (VARIANT* hWnd, VARIANT* hDC, View** prop) 
        { The hWnd and hDC are optional and can be left blank. The prop is actuall the pointer }
        { to the returned value (TheView), which in Delphi is on the left hand side of the method. }  
           TheView := SDKViews.Add();

        { We now set various parameters for TheView that we returned. }
           TheView.Update := FALSE;

           { Obtain the Window Device Context handle to paint on. In this case the PaintBox control }
           FormHwnd := PaintBox1.Canvas.Handle;
           TheView.DC := FormHwnd;

           TheView.MappingMode := MM_TEXT;

        { Set paint area. }        
           TheView.ScreenLeft := 5;
           TheView.ScreenTop :=  5;
           TheView.ScreenWidth := wWidth - 10;
           TheView.ScreenHeight := wHeight - 10;

        { Keep the Aspect ratio to Fixed  }
           TheView.FixedAspectRatio := TRUE;

        { ZoomToExtents draws the graphic to the paint area defined above keeping the same aspect ratio. }
           TheView.ZoomToExtents;

           { Get the current paint area for further use }
           wX := TheView.ScreenLeft;
           wY := TheView.ScreenTop;
           wWidth := TheView.ScreenWidth;
           wHeight := TheView.ScreenHeight;

         { This  method forces a refresh to push the graphic to screen }
           TheView.Refresh;
       end;
       except (exception e)
           Application.MessageBox('Exception occurred: ' + e.AsString(), 'Message Box', mb_OKCancel +  mb_DefButton1);
       end;

   end;
end;